package com.whmskj.xjlhsc.mobie.equipment.controller;

import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.mobie.equipment.entity.SparePart;
import com.whmskj.xjlhsc.mobie.equipment.service.SparePartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: XJLHSC
 * @BelongsPackage: com.whmskj.xjlhsc.mobie.spareparts.controller
 * @Author: lk
 * @CreateTime: 2025-07-09
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@Tag(description = "设备备件", name = "设备备件")
@RequestMapping("/sparePart")
@RequiredArgsConstructor
public class SparePartController {

    private final SparePartService sparePartService;

    @GetMapping("/list")
    @Operation(description = "设备备件列表", summary = "设备备件列表")
    public Result getList(SparePart fo) {
        return Result.success(sparePartService.getList(fo));
    }

    @GetMapping("/{id}")
    @Operation(description = "设备备件详情", summary = "设备备件详情")
    public Result get(@PathVariable Long id) {
        return Result.success(sparePartService.getById(id));
    }

    @GetMapping("/selectPartTypes")
    @Operation(description = "设备备件类型下拉列表", summary = "设备备件类型下拉列表")
    public Result selectPartTypes() {
        return Result.success(sparePartService.selectPartTypes());
    }

    @PostMapping
    @Operation(description = "添加设备备件", summary = "添加设备备件")
    public Result add(@RequestBody SparePart sparePart) {
        return sparePartService.save(sparePart) ? Result.success() : Result.error("添加失败");
    }

    @PutMapping
    @Operation(description = "修改设备备件", summary = "修改设备备件")
    public Result update(@RequestBody SparePart sparePart) {
        return sparePartService.updateById(sparePart) ? Result.success() : Result.error("修改失败");
    }

    @DeleteMapping
    @Operation(description = "删除设备备件", summary = "删除设备备件")
    public Result delete(@RequestBody SparePart sparePart) {
        return sparePartService.removeById(sparePart) ? Result.success() : Result.error("删除失败");
    }

}
